# -*- coding: utf-8 -*-
########################################################################
#   Pax-Selector. Copyright 2010, Hector Sanjuán.                      #
#                                                                      #
#   Pax-selector is free software: you can redistribute it and/or      #
#   modify it under the terms of the GNU General Public License as     #
#   published by the Free Software Foundation, either version 3 of     #
#   the License, or any later version.                                 #
#                                                                      #
#   Pax-selector is distributed in the hope that it will be useful,    #
#   but WITHOUT ANY WARRANTY; without even the implied warranty of     #
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the      #
#   GNU General Public License for more details.                       #
#                                                                      #
#   You should have received a copy of the GNU General Public License. #
#   If not, see <http://www.gnu.org/licenses/>.                        #
#                                                                      #
########################################################################

class PaxSelector
  module Views
    class Customlist < Mustache
      
      def fields
        r = "<th>ID</th>"
        @list.customfields.each do | field |
          r+="<th>#{field}</th>\n"
        end
        return {:fieldnames => r}
      end
      
      def participants
        tablefields = []       
        @list.each do |participant|
          id = participant[:id]
          values = "<td>#{id}</td>"
          @list.customfields.each do | field |
            values+="<td>#{participant[field]}</td>\n"
          end
          field = {:field => 
            "<tr>"+values+"</tr>"
          }
          tablefields << field
        end
        return tablefields
      end
      
      def selectables
        selectables = []
        for i in 1..@list.size
          selectables << { :select => "<li id=\"#{i}\">#{i}</li>" }
        end
        return selectables
      end
      
    end
  end
end
